package com.moyingren.springcloud.config;

import com.google.common.net.HttpHeaders;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ConfigBean {
//    @Bean
//    @LoadBalanced//开启负载均衡
//    public RestTemplate getRestTemplate(){
//        return new RestTemplate();
//    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        RestTemplate template = new RestTemplateBuilder()
//                .basicAuthentication("username", "password")
                .basicAuthorization("admin", "123456")
                .build();
        return template;
    }

/*    @Bean//自定义负载均衡规则
    public IRule myRule(){
        return new RandomRule();
    }*/

}
